[qwen] Drop fp32 LayerNorm casts in Qwen3.5 text model on ORT >= 1.26 - #361
Conversation
Agent-Logs-Url: https://github.com/xadupre/mbext/sessions/c8bbd555-a54b-44b0-af26-04edde9ce0ce Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
📂 Impacted Files2 file(s) changed in this pull request: 🔵 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #361 +/- ##
==========================================
- Coverage 79.96% 79.89% -0.08%
==========================================
Files 25 25
Lines 7837 7843 +6
==========================================
- Hits 6267 6266 -1
- Misses 1570 1577 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot it seems it does not work if it does not use the nightly versions |
Agent-Logs-Url: https://github.com/xadupre/mbext/sessions/f2603def-6691-4404-852c-0551265dc4f1 Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Gated the cast removal on |
Ports microsoft/onnxruntime-genai#2101:
Qwen35TextModelwas forcing every RMSNorm to cast IO to fp32, inserting ~216 Cast nodes (108 to-fp32 + 108 to-fp16) aroundSkipSimplifiedLayerNormalizationin a 24-layer build. Upstream measurements show +13% gen tps on RTX 5080 and +9% on Intel iGPU with output remaining structurally identical, so the casts are removed — but only when the runtime is recent enough.Changes
modelbuilder/builders/qwen.py— gate the fivelayernorm_attrs["cast"]assignments (use_fp32,root_input,skip_input,output_0,output_3) inQwen35TextModel.__init__on the installedonnxruntimeversion. On ORT >= 1.26 (nightly) the assignments are dropped, matching upstream onnxruntime-genai#2101. On older ORT releases the explicit fp32 cast wrapping is preserved, since the native fp16SkipSimplifiedLayerNormalizationkernel loses precision across Qwen3.5's 36+ layers.tests/fast/test_random_qwen3_5.py— addtest_qwen3_5_fp16_no_layernorm_fp32_casts: builds a tiny fp16 Qwen3.5 ONNX model and walks the graph to assert no Cast-to-fp32 feeds, and no Cast-from-fp32 consumes, anySkipSimplifiedLayerNormalizationop. Verified to fail (15 offending casts) when the removed assignments are reintroduced. The test is skipped when running ononnxruntime < 1.26.Diff sketch